package com.hl.sfzy.service.content.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.entity.content.PublicWelfare;
import com.hl.sfzy.mapper.content.publicwelfare.PublicWelfareMapper;
import com.hl.sfzy.service.content.PublicWelfareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

@Service
public class PublicWelfareServiceImpl implements PublicWelfareService {


    @Autowired
    private PublicWelfareMapper publicWelfareMapper;

    @Override
    public PageInfo<PublicWelfare> getAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<PublicWelfare> all = publicWelfareMapper.getAll();
        PageInfo<PublicWelfare> publicWelfarePageInfo = new PageInfo<>(all);
        return publicWelfarePageInfo;
    }


    @Override
    public PublicWelfare getById(Integer id) {
        return publicWelfareMapper.getById(id);
    }

    @Override
    public int add(PublicWelfare publicWelfare) {
        int add = publicWelfareMapper.add(publicWelfare);
        return add;
    }

    @Override
    public int update(PublicWelfare publicWelfare) {
       return publicWelfareMapper.update(publicWelfare);

    }

    @Override
    public int delete(Integer id) {
        int delete = publicWelfareMapper.delete(id);
        return delete;
    }

    @Override
    public PageInfo<PublicWelfare> search(String keyword, LocalDateTime startTime, LocalDateTime endTime, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<PublicWelfare> publicWelfares = publicWelfareMapper.search(keyword, startTime, endTime);
        PageInfo<PublicWelfare> publicWelfarePageInfo = new PageInfo<>(publicWelfares);
        return publicWelfarePageInfo;
    }
}
